<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var nums = [1, 1, 1, 2, 3];

    function asd(nums) {
      var conut = 0;
      var len = nums.length;
      for (let i = 0; i < len; i++) {
        if (nums[i] != nums[i + 1]) {
          conut++;
          console.log(conut);
        } else {
          nums[i - conut + 1] = nums[i + 1];
        }
      }
      console.log(nums);
      return len - conut;
    };
    console.log(asd(nums));
  </script>
</body>

</html>